package com.by.common.controller;

import com.by.common.bean.ResultBean;
import com.by.common.ex.BusinessException;
import com.by.common.ex.ValidateException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//异常增强注解
public class GlobalExceptionController extends BaseController {

    /**
     * 捕获后端验证异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(ValidateException.class)
    public ResultBean handlerValidationException(ValidateException e) {
        return fail("验证失败", e.getErrorMap());
    }


    @ExceptionHandler(BusinessException.class)
    public ResultBean handlerBusinessException(BusinessException e){
        return fail("业务异常",e.getMessage());
    }
}
